package main

import (
	"common"
	"io"
	"net"
	"server/proc"
	"utils"
)

type Processor struct {
	Conn net.Conn
}

func (this *Processor) Process() (err error) {
	defer this.Conn.Close()

	for {
		ut := &utils.Utils{
			Conn: this.Conn,
		}
		mes, err := ut.ReadMes()
		if err != nil {
			if err == io.EOF {
				err = io.EOF
			}
			return err

		}
		switch mes.Type {
			case common.LoginType:
				us := &proc.UserProc{
					Conn: this.Conn,
				}
				err = us.Login(&mes)
			case common.REGISTERTYPE:
				us := &proc.UserProc{
					Conn: this.Conn,
				}
				err = us.Register(&mes)
			case common.SmsMessageType:
				sp := &proc.SmsProc{}
				sp.SendGroupMessage(&mes)
		}
	}

}

